// 日志文件
var log4js = require('log4js');
var path = require("path");
var config =   {
    "appenders": {
        "console": {
            "type": "console"
        },
        "trace": {
            "type": "file",
            "filename":  path.resolve(__dirname,"../../log/access.log") ,
            "maxLogSize ": 31457280
        },
        "http": {
            "type": "logLevelFilter",
            "appender": "trace",
            "level": "trace",
            "maxLevel": "trace"
        },
        "info": {
            "type": "dateFile",
            "filename": path.resolve(__dirname,"../../log/info") ,
            "pattern": "-yyyy-MM-dd.log",
            "alwaysIncludePattern": true,
            "compress": true
        },
        "maxInfo": {
            "type": "logLevelFilter",
            "appender": "info",
            "level": "debug",
            "maxLevel": "info"
        },
        "error": {
            "type": "dateFile",
            "filename": path.resolve(__dirname,"../../log/error"),
            "pattern": "-yyyy-MM-dd.log",
            "alwaysIncludePattern": true,
            "compress": true
        },
        "minError": {
            "type": "logLevelFilter",
            "appender": "error",
            "level": "error"
        }
    },
    "categories": {
        "default": {
            "appenders": [
                "console",
                "http",
                "maxInfo",
                "minError"
            ],
            "level": "all"
        }
    }
};

//配置日志的输出级别,共ALL<TRACE<DEBUG<INFO<WARN<ERROR<FATAL<MARK<OFF八个级别,default level is OFF

//只有大于等于日志配置级别的信息才能输出出来，可以通过category来有效的控制日志输出级别

/*
 var logger = log4js.getLogger("global:");
 logger.level = 'error';
 logger.debug("debug---asdasdasd");
 logger.info("info--sadadasd");
 logger.error("error--sadadasd");
 logger.error("error--sadadasd");
 logger.fatal("fatel--sadadasd");
 logger.trace("trace--sadadasd");
 *
 * */

//根据运行环境配置参数，具体可以根据自己的需求来

if(process.env.NODE_ENV == "production"){
    //生产环境
    config.categories.default.appenders = ["http","maxInfo","minError"];
    config.categories.default.level = "info";
}else{
    config.categories.default.appenders = ["console"];
    config.categories.default.level = "all";
}

log4js.configure(config);

module.exports = log4js;


/*
*
*    var log4js = require('log4js');
    var logger = require("./lib/logger").getLogger("app.js"); //表示这个日志来着于 app.js文件
    //logger.level = 'error';      //可以不设置，不设置就使用之前配置的default里面的等级
* */